package org.geektimes.projects.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tom
 * @since 2021/3/31 21:58
 */
@RestController
public class RestTestApi {

    @GetMapping("hello/world")
    public String getTest(){
        return "hello, world";
    }

    @PostMapping("a/b")
    public String postNoArgs(){
        return "a";
    }

    @PostMapping("a/c")
    public String postWithArgs(String test){
        return test;
    }

    @PostMapping("a/d")
    public User postJson(String test){
        User user = new User();
        user.setName("tom");
        user.setAge(32);
        user.setTest(test);
        return user;
    }

    @PostMapping("a/e")
    public User post(@RequestBody User user){
        return user;
    }

    public static class User{
        private String name;
        private Integer age;
        private String test;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public String getTest() {
            return test;
        }

        public void setTest(String test) {
            this.test = test;
        }
    }
}
